/**
 * dg
 */
package com.thinkgem.jeesite.zmis.dg.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.zmis.dg.entity.ZmisDg;
import com.thinkgem.jeesite.zmis.dg.service.ZmisDgService;

/**
 * 顶岗项目登记表Controller
 * @author ll
 * @version 2017-10-11
 */
@Controller
@RequestMapping(value = "${adminPath}/dg/zmisDg")
public class ZmisDgController extends BaseController {

	@Autowired
	private ZmisDgService zmisDgService;
	
	@ModelAttribute
	public ZmisDg get(@RequestParam(required=false) String id) {
		ZmisDg entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = zmisDgService.get(id);
		}
		if (entity == null){
			entity = new ZmisDg();
		}
		return entity;
	}
	
	@RequiresPermissions("dg:zmisDg:view")
	@RequestMapping(value = {"list", ""})
	public String list(ZmisDg zmisDg, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ZmisDg> page = zmisDgService.findPage(new Page<ZmisDg>(request, response), zmisDg); 
		model.addAttribute("page", page);
		return "zmis/dg/zmisDgList";
	}

	@RequiresPermissions("dg:zmisDg:view")
	@RequestMapping(value = "form")
	public String form(ZmisDg zmisDg, Model model) {
		model.addAttribute("zmisDg", zmisDg);
		return "zmis/dg/zmisDgForm";
	}

	@RequiresPermissions("dg:zmisDg:edit")
	@RequestMapping(value = "save")
	public String save(ZmisDg zmisDg, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, zmisDg)){
			return form(zmisDg, model);
		}
		zmisDgService.save(zmisDg);
		addMessage(redirectAttributes, "保存顶岗项目成功");
		return "redirect:"+Global.getAdminPath()+"/dg/zmisDg/?repage";
	}
	
	@RequiresPermissions("dg:zmisDg:edit")
	@RequestMapping(value = "delete")
	public String delete(ZmisDg zmisDg, RedirectAttributes redirectAttributes) {
		zmisDgService.delete(zmisDg);
		addMessage(redirectAttributes, "删除顶岗项目成功");
		return "redirect:"+Global.getAdminPath()+"/dg/zmisDg/?repage";
	}

}